home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume3 / uumail < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  54.2 KB

  1. From: genrad!rice!neuro1!sob
  2. Newsgroups: mod.sources
  3. Subject: uumail -- an opath/pathalias based uucp mailer
  4. Approved: jpn@panda.UUCP
  5. Reply-To: sob@neuro1.UUCP (Stan Barber)
  6. Organization: Neurophysiology, Baylor College of Medicine, Houston, Tx
  7.  
  8. Mod.sources:  Volume 3, Issue 49
  9. Submitted by: genrad!rice!neuro1!sob
  10.  
  11.  
  12. Following is the shar for uumail, my version of a pathalias-database
  13. mailer. This program can also understand domain names in the uucp
  14. tradition (! over @) and can handle the new flags in 4.3 uucp.
  15.  
  16. Please read the README for more information.
  17.  
  18. This program has been checked-out on a Sun-2, Masscomp, and Sperry5000.
  19.  
  20. Thanks to Eric Roskos for the use of opath.
  21.  
  22. Please forward comments and bug fixes to me at sob@rice.edu or 
  23. ihnp4!shell!neuro1!sob or texsun!drilltech!sob
  24.  
  25. Stan Barber
  26. Baylor College of Medicine
  27. Houston, Texas
  28.  
  29. #! /bin/sh
  30. # This is a shell archive, meaning:
  31. # 1. Remove everything above the #! /bin/sh line.
  32. # 2. Save the resulting text in a file.
  33. # 3. Execute the file with /bin/sh (not csh) to create the files:
  34. #    README
  35. #    README.orig
  36. #    address.1
  37. #    address.c
  38. #    domains
  39. #    gethostnam.c
  40. #    getpath.c
  41. #    makefile
  42. #    opath.3
  43. #    opath.c
  44. #    palias
  45. #    rmail.c
  46. #    uuconf.h
  47. #    uumail.1
  48. #    uumail.c
  49. #    uupath.1
  50. #    uupath.c
  51. # This archive created: Wed Nov 20 07:16:35 1985
  52. export PATH; PATH=/bin:$PATH
  53. echo shar: extracting "'README'" '(2366 characters)'
  54. if test -f 'README'
  55. then
  56.     echo shar: will not over-write existing file "'README'"
  57. else
  58. sed 's/^X//' << \SHAR_EOF > 'README'
  59. This is an updated version of uumail (and uupath) that can 
  60. access a pathalias-generated database to facilitate routine mail.
  61.  
  62. These program can cope with DBM and standard line-oriented forms of 
  63. pathalias-generated databases.
  64.  
  65. This version of uumail can be used as uupath by linking uumail to
  66. uupath. Also, this version can handle domain addresses (user@host.domain).
  67. You can put as many addresses on a line as you like.
  68.  
  69. There are some compile flags to be aware of when making uumail.
  70. Here is a list of them.
  71.  
  72. DEBUG compiles in the debugging code.
  73. OPATH causes the opath subroutine to be used to resolve addresses.
  74. If you do not use this flag, you cannot use the user@host.domain style
  75. addresses with uumail.
  76. DBM causes uumail to use the DBM format patalias database. If you do not
  77. have the dbm libraries, do not use this flag.
  78. XSYSIII will make adjustments for system that are derived from UNIX System
  79. III or System V.
  80. NOGRADE should be used if your uux does not understand the -g flag.
  81. NORETURN should be used if your uux does not understand the -a flag.
  82. LOG will enable logging of uumail traffic.
  83. UGLYUUCP causes the From_ line produced by uumail to contain the
  84. "remote from hostname" string.
  85. GETHOSTNAME will cause the c-library gethostname to be used. If you
  86. are a BSD site, define this.
  87. XSYSTEMNAME will cause the systemname to be derived from the file
  88. /usr/lib/uucp/SYSTEMNAME. This should be defined if your machine
  89. is a Sperry 5000.
  90.  
  91.  
  92. Here is the mailer segment of a sendmail configuration file that you
  93. can use to define the uumail program as a mailer.
  94. -------------------------------------------------------------------
  95. ############################################################
  96. #### This is a special mailer that takes advantage of    ###
  97. #### usemap database for addresses to UUCP sites         ###
  98. ############################################################
  99.  
  100. Muumail, P=/usr/lib/uucp/uumail,F=sDFhuUM,S=13,R=23,M=1000000,
  101.     A=uumail -h -gC -f$g $h!$u
  102. --------------------------------------------------------------
  103. Please be sure that the S= and R= rules are correct for your
  104. system. They should match the uucp mailer rules exactly.
  105.  
  106. A manual page for uumail and uupath are included.
  107.  
  108. Please forward comments and bug fixes to me at sob@rice.edu or 
  109. ihnp4!shell!neuro1!sob or texsun!drilltech!sob
  110.  
  111. XStan Barber
  112. Baylor College of Medicine
  113. Houston, Texas
  114. SHAR_EOF
  115. if test 2366 -ne "`wc -c < 'README'`"
  116. then
  117.     echo shar: error transmitting "'README'" '(should have been 2366 characters)'
  118. fi
  119. fi # end of overwriting check
  120. echo shar: extracting "'README.orig'" '(875 characters)'
  121. if test -f 'README.orig'
  122. then
  123.     echo shar: will not over-write existing file "'README.orig'"
  124. else
  125. sed 's/^X//' << \SHAR_EOF > 'README.orig'
  126. The makefile can make two programs.  One is a filter that can be used
  127. to expand network paths.  To install it you rename the program that you
  128. want filtered.  The new file name is simply the old one with a period (.) 
  129. appended to the end.  The filter program (filter) is then renamed to the 
  130. original name of the program to be filtered.
  131.     ie mail druxn!kak gets converted to
  132.     mail. pur-ee!decvax!...!druxn!kak
  133.  
  134. The second file the makefile makes is uupath.  This will tell you the network
  135. paths of its arguments
  136. name tell you the path to it.
  137.  
  138. Don't forget to modify the defines for the location of the network map.  The
  139. default location is /etc/usemap
  140.  
  141. If you have any questions just ask.
  142.  
  143.             Jeff Donnelly  (217) 333-6106
  144.             University of Illinois
  145.             pur-ee!uiucdcs!donnelly
  146.  
  147. Jeff may not help much -- his new number is 217-333-7937;
  148. Kolstad can help some also:  214-669-3700
  149. SHAR_EOF
  150. if test 875 -ne "`wc -c < 'README.orig'`"
  151. then
  152.     echo shar: error transmitting "'README.orig'" '(should have been 875 characters)'
  153. fi
  154. fi # end of overwriting check
  155. echo shar: extracting "'address.1'" '(3563 characters)'
  156. if test -f 'address.1'
  157. then
  158.     echo shar: will not over-write existing file "'address.1'"
  159. else
  160. sed 's/^X//' << \SHAR_EOF > 'address.1'
  161. X.TH ADDRESS 1 local
  162. X.SH NAME
  163. address - display the path generated by \fBdeliver\fR for an
  164. RFC822-format address.
  165. X.SH SYNOPSIS
  166. address rfc-address [ ... ]
  167. X.SH DESCRIPTION
  168. This program allows you to check the UUCP mail routing path that will
  169. be generated by the UUCP mailer \fBdeliver\fR if you specify an
  170. RFC822-format address \fBrfc-address\fR in the ``To:'' field of the mail header.
  171. XFor each RFC-style address on the command line, \fBaddress\fR echoes the
  172. address to the standard output, followed by a colon, followed by
  173. the UUCP address that will be used to send the message to that address.
  174.  
  175. X.SH "ADDRESS FORMAT"
  176. Briefly, the RFC822-format address is of the form
  177. X.nf
  178. X.sp 1
  179.     <localaddress>@<hostname>.<network>
  180. X.sp 1
  181. X.fi
  182. where <hostname> is the name of the system you are sending the message
  183. to, <network> is a modifier for <hostname> identifying the network in
  184. which the address is to be interpreted (UUCP, ARPA, MAILNET, CSNET, etc);
  185. and <localaddress> is an address string to be interpreted on the host
  186. machine.
  187.  
  188. The <localaddress> field may contain further remote addresses to be
  189. interpreted on the host machine.  Typically this will be an address for
  190. mailing via another network; and in particular, the <localaddress> may
  191. (recursively) be identical in format to the RFC address, but with
  192. the symbol `%' replacing the symbol `@' in the standard address format.
  193. Where this form is used, the rightmost % is replaced by an
  194. @ before the host machine sends the message out.
  195.  
  196. On our system, the presently
  197. valid <network>s are UUCP, ARPA, CSNET, and MAILNET.
  198. The recently proposed UUCP domain names are also accepted, although
  199. they are treated the same as plain ``UUCP''.
  200. Omitting
  201. the <network> causes the network to default to UUCP.  The <hostname>
  202. should be the name of a remote machine to which the message is
  203. directed; see \fI/usr/lib/uucp/uuaddress.alpha\fR for a list of all
  204. known UUCP hostnames.  It is \fInot\fR necessary to specify a UUCP pathname
  205. when using this format; the pathname is automatically determined for you
  206. and substituted into the address before mailing.  The selected pathname
  207. is determined using the \fBpathalias\fR database, and is supposed
  208. to be optimal, taking into consideration information provided by
  209. each site about how often they send mail out, etc.
  210.  
  211. X.SH EXAMPLES
  212. X.HP 5
  213. joe
  214. X.br
  215. The message is sent to the user ``joe'' on the local system.
  216. X.HP 5
  217. joe@ucbvax
  218. X.br
  219. The message is sent to joe on the UUCP system named ``ucbvax''; this
  220. address is automatically translated to a proper (and ostensibly
  221. optimal) UUCP path.
  222. X.HP 5
  223. joe@ucbvax.UUCP
  224. X.br
  225. XSame as joe@ucbvax
  226. X.HP 5
  227. joe@ucbvax.ARPA
  228. X.br
  229. The message is addressed to joe at ucbvax, using the ARPA network.
  230. The message will be routed to the ARPAnet via a UUCP-ARPAnet gateway.
  231. X.HP 5
  232. joe%mit-multics.ARPA@ucbvax
  233. X.br
  234. The message is sent to ucbvax, who then uses the address
  235. joe@mit-multics.ARPA to send the message on to mit-multics via the
  236. ARPAnet.  Since ucbvax is on the arpanet, this address will work correctly
  237. (as long as there is someone named joe on the MIT multics machine).
  238. X.HP 5
  239. joe%vanderbilt.MAILNET%mit-multics.ARPA@ucbvax
  240. X.br
  241. The message is sent via UUCP to ucbvax, who then sends the message
  242. to mit-multics via the arpanet; mit-multics then sends the message
  243. to joe@vanderbilt via MAILNET.  Since the above machines each have access
  244. to the networks named in the address, this address will work correctly.
  245. X.SH FILES
  246. /usr/lib/uucp/domains - Domain/gateway table
  247. X.br
  248. /usr/lib/uucp/archive - Pathalias database
  249. X.SH "SEE ALSO"
  250. opath(3)
  251. X.SH AUTHOR
  252. Eric Roskos, PE SDC, 1/16/85
  253. SHAR_EOF
  254. if test 3563 -ne "`wc -c < 'address.1'`"
  255. then
  256.     echo shar: error transmitting "'address.1'" '(should have been 3563 characters)'
  257. fi
  258. fi # end of overwriting check
  259. echo shar: extracting "'address.c'" '(885 characters)'
  260. if test -f 'address.c'
  261. then
  262.     echo shar: will not over-write existing file "'address.c'"
  263. else
  264. sed 's/^X//' << \SHAR_EOF > 'address.c'
  265. /*
  266.  * address - run opath to see what a translated RFC822 address will come
  267.  * out as.
  268.  *
  269.  * By E. Roskos 1/16/85
  270.  * $Log:    address.c,v $
  271.  * Revision 1.2  85/09/16  18:31:53  sob
  272.  * Added DEBUG flag
  273.  * 
  274.  * Revision 1.1  85/09/16  17:50:24  sob
  275.  * Initial revision
  276.  * 
  277.  */
  278. #define _DEFINE
  279. #include "uuconf.h"
  280.  
  281. static char rcsid[] = "$Header: address.c,v 1.2 85/09/16 18:31:53 sob Exp $";
  282.  
  283. char *opath();
  284. int Debug;
  285.  
  286. main(argc,argv)
  287. int argc;
  288. char **argv;
  289. {
  290. char *p;
  291. int uswitch;
  292.  
  293.     if (argc < 2)
  294.     {
  295.         fprintf(stderr,"usage: %s rfcaddress [...]\n",
  296.             argv[0]);
  297.         exit(1);
  298.     }
  299.  
  300.     while (--argc)
  301.     {
  302.         p = *++argv;
  303.         if (*p=='-')
  304.         {
  305.             switch(*++p)
  306.             {
  307.             case 'u': uswitch++;
  308.                   continue;
  309.             case 'd': Debug++;
  310.                       continue;
  311.             default:  printf("unknown switch: %c\n",*p);
  312.                   continue;
  313.             }
  314.             continue;
  315.         }
  316.         printf("%s: %s\n",p,uswitch?oupath(p):opath(p));
  317.     }
  318.  
  319.     exit(0);
  320. }
  321. SHAR_EOF
  322. if test 885 -ne "`wc -c < 'address.c'`"
  323. then
  324.     echo shar: error transmitting "'address.c'" '(should have been 885 characters)'
  325. fi
  326. fi # end of overwriting check
  327. echo shar: extracting "'domains'" '(1093 characters)'
  328. if test -f 'domains'
  329. then
  330.     echo shar: will not over-write existing file "'domains'"
  331. else
  332. sed 's/^X//' << \SHAR_EOF > 'domains'
  333. #
  334. # Domain Table
  335. #
  336. # Format: <domain>,<prefix>,<suffix>,<template>
  337. #
  338. # Where <template> may contain:
  339. #       %P - prefix string
  340. #       %S - suffix string
  341. #       %U - destination user name
  342. #       %N - destination site name
  343. #       %D - destination site name with domain suffix
  344. #       %% - a percent (%) sign
  345. #       %R - pathalias route to the destination site
  346. #
  347. X.WA.UUCP,,,%R!%U
  348. X.OR.UUCP,,,%R!%U
  349. X.N-CA.UUCP,,,%R!%U
  350. X.S-CA.UUCP,,,%R!%U
  351. X.MTN.UUCP,,,%R!%U
  352. X.S-CEN.UUCP,,,%R!%U
  353. X.MID-W.UUCP,,,%R!%U
  354. X.S-EAST.UUCP,,,%R!%U
  355. X.ATL.UUCP,,,%R!%U
  356. X.N-ENG.UUCP,,,%R!%U
  357. X.HI.UUCP,,,%R!%U
  358. X.W-CAN.UUCP,,,%R!%U
  359. X.E-CAN.UUCP,,,%R!%U
  360. X.EUR.UUCP,,,%R!%U
  361. X.UK.UUCP,,,%R!%U
  362. X.AUS.UUCP,,,%R!%U
  363. X.ISRAEL.UUCP,,,%R!%U
  364. X.ATT.UUCP,>ihnp4,,%P!%D!%U
  365. X.HP.UUCP,,,%R!%U
  366. X.PE.UUCP,,,%R!%U
  367. X.UUCP,,,%R!%U
  368. X.CSNET,>rice,,%P!%U%%%D@CSNET-RELAY.ARPA
  369. X.MAILNET,>rice,,%P!%U%%%D@MULTICS.MIT.EDU
  370. # .BITNET,>rice,,%P!%U%%%D@WISCVM.ARPA
  371. X.XEROX,>rice,,%P!%U.%D@XEROX.ARPA
  372. X.DEC,>decwrl,,%P!%U@%D
  373. X.ARPA,>rice,,%P!%U@%D
  374. X.EDU,>rice,,%P!%U@%D
  375. X.COM,>rice,,%P!%U@%D
  376. X.GOV,>rice,,%P!%U@%D
  377. X.MIL,>rice,,%P!%U@%D
  378. X.OTH,>rice,,%P!%U@%D
  379. X.BITNET,>psuvax,,%P!%U@%D
  380. SHAR_EOF
  381. if test 1093 -ne "`wc -c < 'domains'`"
  382. then
  383.     echo shar: error transmitting "'domains'" '(should have been 1093 characters)'
  384. fi
  385. fi # end of overwriting check
  386. echo shar: extracting "'gethostnam.c'" '(1266 characters)'
  387. if test -f 'gethostnam.c'
  388. then
  389.     echo shar: will not over-write existing file "'gethostnam.c'"
  390. else
  391. sed 's/^X//' << \SHAR_EOF > 'gethostnam.c'
  392. #ifndef lint
  393. static char    sccsid[] = "@(#)gethostnam.c    6.1 (down!honey) 85/01/21";
  394. static char    rcsid[] = "$Header: gethostnam.c,v 6.2 85/08/03 00:25:16 UUCP Exp $";
  395. #endif lint
  396.  
  397. #ifndef GETHOSTNAME
  398. #include "uuconf.h"
  399.  
  400. void
  401. gethostname(name, len)
  402. char    *name;
  403. {
  404.     FILE    *whoami, *fopen(), *popen();
  405.     char    *ptr, *index();
  406. #ifdef SYSIII
  407.     struct utsname utsn;
  408. #endif
  409.  
  410.     *name = '\0';
  411. #ifdef SYSIII
  412.     if (uname(&utsn) != -1)
  413.     {
  414.         strcpy(name,utsn.nodename);
  415.         len = strlen(name);
  416.           return;
  417.     }
  418. #endif
  419.  
  420.     /* try /etc/whoami */
  421.     if ((whoami = fopen("/etc/whoami", "r")) != 0) {
  422.         (void) fgets(name, len, whoami);
  423.         (void) fclose(whoami);
  424.         if ((ptr = index(name, '\n')) != 0)
  425.             *ptr = '\0';
  426.     }
  427.     if (*name)
  428.         return;
  429.  
  430.     /* try /usr/include/whoami.h */
  431.     if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) {
  432.         while (!feof(whoami)) {
  433.             char    buf[100];
  434.  
  435.             if (fgets(buf, 100, whoami) == 0)
  436.                 break;
  437.             if (sscanf(buf, "#define sysname \"%[^\"]\"", name))
  438.                 break;
  439.         }
  440.         (void) fclose(whoami);
  441.         if (*name)
  442.             return;
  443.     }
  444.  
  445.     /* ask uucp */
  446.     if ((whoami = popen("uuname -l", "r")) != 0) {
  447.         (void) fgets(name, len, whoami);
  448.         (void) pclose(whoami);
  449.         if ((ptr = index(name, '\n')) != 0)
  450.             *ptr = '\0';
  451.     }
  452.     if (*name)
  453.         return;
  454.     
  455.     /* failure */
  456.     return;
  457. }
  458. #endif GETHOSTNAME
  459. SHAR_EOF
  460. if test 1266 -ne "`wc -c < 'gethostnam.c'`"
  461. then
  462.     echo shar: error transmitting "'gethostnam.c'" '(should have been 1266 characters)'
  463. fi
  464. fi # end of overwriting check
  465. echo shar: extracting "'getpath.c'" '(2798 characters)'
  466. if test -f 'getpath.c'
  467. then
  468.     echo shar: will not over-write existing file "'getpath.c'"
  469. else
  470. sed 's/^X//' << \SHAR_EOF > 'getpath.c'
  471. /*
  472.  * Name: getpath -- return the full usenet path of the given name
  473.  *
  474.  * Paramaters: sysname (input) -- The system name to be expanded
  475.  *           pathname (output)  The usenet path of the given system name
  476.  *           pathfile (input) the file to search for the system name
  477.  *
  478.  * Returns: EX_OK     -- path found
  479.  *        EX_NOHOST -- path not found
  480.  *        EX_NOINPUT-- unable to open usemap
  481.  *
  482.  * Author: J. Donnelly   3/82
  483.  *
  484.  */
  485.  
  486. /* 22-jun-83 Sheppard
  487.  * modified to rewind path file (if open), rather than open again
  488.  *
  489.  * $Log:    getpath.c,v $
  490.  * Revision 1.9  85/11/14  20:21:49  sob
  491.  * Added #ifdef DEBUG to allow compilation without DEBUG
  492.  * 
  493.  * Revision 1.8  85/11/08  03:04:49  sob
  494.  * release version
  495.  * 
  496.  * Revision 1.7  85/09/30  02:47:40  sob
  497.  * Altered to use path filename from global variable.
  498.  * 
  499.  * Revision 1.6  85/08/03  00:48:57  UUCP
  500.  * Cleaned up with lint.
  501.  * Stan Barber
  502.  * 
  503.  * Revision 1.5  85/07/19  17:45:13  UUCP
  504.  * Added \t as a valid seperation character for the database
  505.  * in the non DBM case. This is what pathalias uses.
  506.  * 
  507.  * Revision 1.4  85/07/19  16:44:07  UUCP
  508.  * revised to return proper things in accordance with sysexits
  509.  * Stan
  510.  * 
  511.  * Revision 1.3  85/07/11  19:30:31  sob
  512.  * added "uuconf.h" include file and deleted duplicated information
  513.  * 
  514.  * Revision 1.2  85/07/10  18:30:59  sob
  515.  * updated to add DBM capabilities
  516.  * Stan Barber, Baylor College of Medicine
  517.  * 
  518.  * Revision 1.1  85/07/10  18:03:28  sob
  519.  * Initial revision
  520.  * 
  521.  */
  522.  
  523. #include    "uuconf.h"
  524.  
  525. static char rcsid[] = "$Header: getpath.c,v 1.9 85/11/14 20:21:49 sob Exp $";
  526.  
  527.  
  528.  
  529. XFILE * fopen (), *in;
  530.  
  531. getpath (sysname, pathname)
  532. char   *sysname, *pathname;
  533. {
  534.     char    name[NAMESIZ],*p,t;
  535.  
  536. #ifdef DBM
  537.     datum lhs,rhs;
  538. #endif
  539. #ifdef DEBUG
  540. if (Debug>2)
  541.     printf("In getpath: Sysname = %s, Pathfile = %s\n",sysname,paths);
  542. #endif
  543. #ifdef DBM
  544.    if (dbminit(paths) <0) return(EX_NOINPUT);
  545.         lhs.dptr = sysname;
  546.     lhs.dsize = strlen(sysname)+1;
  547.     rhs = fetch(lhs);
  548.     if (rhs.dptr == NULL) return(EX_NOHOST); /* no name found */
  549.     strcpy(pathname,rhs.dptr);
  550.         return(EX_OK);            /* system name found */
  551.  
  552. #else
  553. if (in == NULL) {
  554.     if ((in = fopen(paths, "r")) == NULL)
  555.         return(EX_NOINPUT);
  556.     }
  557.     else
  558.     rewind(in);
  559.  
  560.     for (;;)
  561.     {
  562.     p = &name[0];
  563.     while ((t = getc(in)) != EOF && (*p++ = t) != ' ' && t != '\t'); /* read the system name */
  564.     if( t == EOF) return(EX_NOHOST);
  565.     *--p = '\0';                    /* set end of string */
  566.     p = &name[0];
  567. #ifdef DEBUG
  568.     if (Debug>4) printf("Found %s\n",p);
  569. #endif
  570.     if (strcmp (p,sysname) == 0)
  571.         break;
  572.     while ((getc (in) != '\n'));            /* skip this path */
  573.     }
  574.  
  575.     p = pathname;                    /* save start loc of pathname */
  576.     while ((*pathname++ = getc (in)) != '\n');
  577.     *--pathname = '\0';
  578.     pathname = p;
  579.     return(EX_OK);            /* system name found */
  580. #endif
  581. }
  582. SHAR_EOF
  583. if test 2798 -ne "`wc -c < 'getpath.c'`"
  584. then
  585.     echo shar: error transmitting "'getpath.c'" '(should have been 2798 characters)'
  586. fi
  587. fi # end of overwriting check
  588. echo shar: extracting "'makefile'" '(2613 characters)'
  589. if test -f 'makefile'
  590. then
  591.     echo shar: will not over-write existing file "'makefile'"
  592. else
  593. sed 's/^X//' << \SHAR_EOF > 'makefile'
  594. ####################################################################
  595. # makefile for uumail & uupath
  596. # program to integrate with pathalias created uucpmap databases
  597. # programs originally developed by Jeff Donnelly
  598. # updated to use pathalias database by Stan Barber
  599. # $Header: makefile,v 1.3 85/08/03 00:38:33 UUCP Exp $
  600. #
  601. # the following defines should be configured for you site
  602. # add -DDBM to CCFLAGS if your pathalias database used the
  603. # dbm(3) routines
  604. # if you are a ATT system III or system V site
  605. # or a masscomp add the -DSYSIII flags
  606. # If you want to use the opath subroutine to deal with
  607. # domain names add the -DOPATH flag to the CFLAGS line
  608. # you may want to modify the LIBS line to correspond to 
  609. # libraries that you may need at you site
  610. # see conf.h for other changes that may need be made
  611. # IMPORTANT INFORMATION ABOUT UUCP
  612. # If your uucp does not understand the -g (grade) flag
  613. # add the -DNOGRADE flag to CFLAGS.
  614. # If your uucp does not know about the -a (returnto) flag
  615. # add the -DNORETURN flag to CFLAGS
  616. # $Log:    makefile,v $
  617. # Revision 1.3  85/08/03  00:38:33  UUCP
  618. # Added support for shar and RCS.
  619. # Changed name of gethostname to gethostnam to allow RCS to work right.
  620. # Stan Barber
  621. # Revision 1.2  85/07/11  19:28:52  sob
  622. # updated with gethostname.c
  623. # Revision 1.1  85/07/11  19:23:22  sob
  624. # Initial revision
  625. ###############################################################
  626. X.SUFFIXES: .c,v .h,v
  627.  
  628. CFLAGS= -O -DSYSIII -DDEBUG -DOPATH -DUGLYUUCP -DLOG
  629.  
  630. LIBS=
  631.  
  632. X.c,v.c:
  633.     co -q $*.c
  634.  
  635. X.h,v.h:
  636.     co -q $*.h
  637.  
  638. all: uumail rmail
  639.  
  640. uumail: getpath.o uumail.o gethostnam.o opath.o
  641.     cc $(CFLAGS) getpath.o uumail.o gethostnam.o opath.o -o uumail $(LIBS)
  642.  
  643. address:address.o opath.o getpath.o
  644.     cc $(CFLAGS) address.o opath.o getpath.o -o address $(LIBS)
  645.  
  646. getpath.o: getpath.c uuconf.h
  647.  
  648. uupath.o: uupath.c uuconf.h
  649.  
  650. uumail.o: uumail.c uuconf.h
  651.  
  652. gethostnam.o:gethostnam.c
  653.  
  654. address.o:address.c
  655.  
  656. opath.o:opath.c
  657.  
  658. rmail: rmail.c gethostnam.o
  659.     cc $(CFLAGS) rmail.c gethostnam.o -o rmail $(LIBS)
  660.  
  661. lint:
  662.     lint $(CFLAGS) getpath.c uumail.c gethostnam.c opath.c
  663.  
  664. clean: 
  665.     rm -f *.o *.CKP *.BAK *.bak
  666.  
  667. doc: uumail.1 uupath.1 address.1 opath.3
  668.     nroff -man uumail.1 >uumail.cat; nroff -man uupath.1 >uupath.cat; nroff -man address.1 >address.cat; nroff -man opath.3 >opath.cat
  669.  
  670. shar: domains palias rmail.c opath.c address.c uumail.c uuconf.h gethostnam.c uupath.c getpath.c README makefile uumail.1 uupath.1 README.orig opath.3 address.1
  671.     shar domains palias rmail.c opath.c address.c uumail.c uuconf.h gethostnam.c uupath.c getpath.c README makefile uumail.1 uupath.1 README.orig opath.3 address.1> shar.out
  672.  
  673. SHAR_EOF
  674. if test 2613 -ne "`wc -c < 'makefile'`"
  675. then
  676.     echo shar: error transmitting "'makefile'" '(should have been 2613 characters)'
  677. fi
  678. fi # end of overwriting check
  679. echo shar: extracting "'opath.3'" '(4896 characters)'
  680. if test -f 'opath.3'
  681. then
  682.     echo shar: will not over-write existing file "'opath.3'"
  683. else
  684. sed 's/^X//' << \SHAR_EOF > 'opath.3'
  685. X.TH OPATH 3 "PE SDC"
  686. X.SH NAME
  687. opath - Generate a UUCP route from an RFC822 address
  688. X.br
  689. oupath - Generate a UUCP route from a (possibly disconnected) UUCP path
  690. X.SH SYNOPSIS
  691. char *opath(s)
  692. X.br
  693. char *s;
  694. X.sp 1
  695. char *oupath(s)
  696. X.br
  697. char *s;
  698. X.SH DESCRIPTION
  699. These routines use the \fBpathalias\fR database to generate UUCP routing
  700. paths from your local site to specified remote sites on either the UUCP
  701. network or other connected networks.
  702. X.PP
  703. \fBopath\fR takes one argument, an RFC822 address, as described in
  704. ADDRESS(1).  From this, it generates and returns a UUCP path to the site
  705. named in the argument.
  706. X.PP
  707. \fBoupath\fR takes one argument, a UUCP path.  If the next site on this
  708. path is named \fIx\fR, \fBoupath\fR will prepend a path from your site to
  709. \fIx\fR, if \fIx\fR is nonadjacent to your site.  If \fIx\fR is a domain,
  710. i.e. contains a dot (.), \fBoupath\fR will generate a path to a gateway
  711. for this domain.  Note that \fBoupath\fR will \fInot\fR alter the argument
  712. path, other than to make the above transformations; it does not check whether
  713. sites in the argument are adjacent to one another, or whether they represent
  714. an optimal path; it is assumed that if the user has specified a path, then
  715. he wants to use that path.
  716. X.PP
  717. The principal difference between \fBopath\fR and \fBoupath\fR is that the
  718. former gives precedence to ``@'', whereas the latter gives precedence
  719. to ``!''.  The former is intended to be invoked when receiving mail from
  720. a user interface or a non-UUCP source (if the subsequent transport mechanism
  721. is to be UUCP), whereas the latter is intended solely to be used by UUCP
  722. internal software, principally \fBrmail\fR, in routing mail through the
  723. UUCP network.
  724. X.SH "FILES"
  725. \fI/usr/lib/uucp/archive\fR - The pathalias database, in DBM(3) format.
  726. XSee PATHALIAS(1) for information; pathalias is a public-domain program
  727. distributed via the Usenet's net.sources facility.
  728. X.br
  729. X.sp 1
  730. \fI/usr/lib/uucp/domains\fR - The domain/gateway table.  Each line of this
  731. file consists of either a ``#'' followed by arbitrary comment text, or
  732. an entry of the form:
  733. X.br
  734. X.in 1i
  735. <domain>,<path>,<reserved>,<template>
  736. X.br
  737. X.in
  738. Where <domain> is the string (in capital letters) identifying a particular
  739. <path> is a string which may be included at an arbitrary point in the
  740. generated route, <reserved> is currently unused, and <template> is a string
  741. indicating the format of the generated route.
  742. X.PP
  743. The <template> is a printf-style string; it is \fBnot\fR quoted, and
  744. begins at the character immediately following the comma which separates
  745. <template> from <reserved>.  The <template> may consist of arbitrary ASCII
  746. characters, which are copied unchanged into the generated route; or of
  747. a percent (%) sign followed by one of the following characters:
  748. X.IP P
  749. The <path> string is inserted.  The <path> may consist either of a string
  750. which is inserted unchanged; or of the character ``>'' followed by the
  751. name of a UUCP site, in which case the entire <path> string is replaced
  752. with a string representing the path to the named site.  The last token on
  753. this string is the site named in the original <path> string, without a
  754. following ``!''.
  755. X.IP U
  756. The user name from the original address is inserted.
  757. X.IP N
  758. The site name from the original address, with the domain specifiers
  759. removed, is inserted.
  760. X.IP D
  761. The site name from the original address, including the domain specifiers,
  762. is inserted.
  763. X.IP R
  764. The UUCP path to the site named in the original address is looked up in
  765. the pathalias database and inserted.  Note that this path is looked up
  766. only when the %R is seen while scanning the <template>, so an error message
  767. for an invalid site name is generated if and only if it appears in an
  768. address with a domain which contains a %R in its template.
  769. X.PP
  770. When making entries in the domain table, domain names which are a suffix of
  771. another domain name in the table should be ordered such that the longer
  772. string(s) appear first.  For example, .WA.UUCP should preceed .UUCP in
  773. the table.  A linear search is made of the table, and the first domain
  774. found in the table which is a suffix of the domain in the designated address
  775. is used as the domain in generating the routing.
  776. X.PP
  777. XFollowing are some example entries for the domain table.  Note that all
  778. domain names begin with a ``.''.
  779. X.sp 1
  780. X.nf
  781. X.in 1i
  782. # This is a comment
  783. \&.HP.UUCP,,,%R!%U
  784. \&.UUCP,,,%R!%U
  785. \&.CSNET,>decwrl,,%P!%U%%%S@CSNET-RELAY.ARPA
  786. \&.EDU,>ucbvax,,%P!%D
  787. X.in
  788. X.fi
  789. X.sp 1
  790. X.SH "SEE ALSO"
  791. PATHALIAS(1), ADDRESS(1), RMAIL(1)
  792. X.SH "AUTHOR"
  793. Eric Roskos, Perkin-Elmer Corp. SDC.
  794. X.SH "NOTE"
  795. The <reserved> field in the domain table currently has a function which
  796. may be determined by examining the source code for opath.  However, this
  797. function is a vestigal function provided for sites that used an earlier
  798. version of opath; future opath versions will use this field for a different
  799. purpose, and new users of opath therefore should \fBnot\fR use this field.
  800. SHAR_EOF
  801. if test 4896 -ne "`wc -c < 'opath.3'`"
  802. then
  803.     echo shar: error transmitting "'opath.3'" '(should have been 4896 characters)'
  804. fi
  805. fi # end of overwriting check
  806. echo shar: extracting "'opath.c'" '(5753 characters)'
  807. if test -f 'opath.c'
  808. then
  809.     echo shar: will not over-write existing file "'opath.c'"
  810. else
  811. sed 's/^X//' << \SHAR_EOF > 'opath.c'
  812. /*
  813.  * opath.c - get an optimal uucp path from the path database, using an
  814.  * RFC882-style address as input.  The '%' character is properly translated,
  815.  * and gateway-substitution is done to get mail onto other networks.
  816.  *
  817.  *
  818.  * Eric Roskos, Perkin-Elmer Corp. SDC
  819.  * Version 3.2 created 85/09/12 15:21:51
  820.  * $Log:    opath.c,v $
  821.  * Revision 3.7  85/11/14  20:22:16  sob
  822.  * Added #ifdef DEBUG to allow compiliation without DEBUG
  823.  * 
  824.  * Revision 3.6  85/11/08  03:05:22  sob
  825.  * release version
  826.  * 
  827.  * Revision 3.5  85/10/09  03:20:07  sob
  828.  * Added strindex call to make striping the printf stuff more pleasing.
  829.  * 
  830.  * Revision 3.4  85/09/30  02:49:12  sob
  831.  * Updated to use getpath revised by Stan Barber
  832.  * 
  833.  * Revision 3.3  85/09/16  18:32:26  sob
  834.  * This version will use the getpath subroutine used by uupath/uumail
  835.  * and is not dependant on whether it is DBM or not.
  836.  * Also uses the uuconf include file.
  837.  * 
  838.  * Revision 3.2  85/09/16  17:50:07  sob
  839.  * Added to RCS
  840.  * 
  841.  */
  842.  
  843. static char *opathsccsid = "@(#)opath.c    3.2 (peora) 15:21:51 - 85/09/12";
  844. static char opathrcsid[] = "$Header: opath.c,v 3.7 85/11/14 20:22:16 sob Exp $";
  845. #ifdef OPATH
  846. #include "uuconf.h"
  847.  
  848. /**
  849.  ** User-configurable parameters
  850.  **/
  851.  
  852. /**
  853.  ** Global Variables
  854.  **/
  855.  
  856. static char pval[150]; /* the path string is built here */
  857.  
  858. /*
  859.  * the following are used to pass results by side-effect from the domain()
  860.  * routine.
  861.  */
  862.  
  863. static char prefix[80], suffix[80], fullsite[80];
  864.  
  865. /**
  866.  ** Subroutines
  867.  **/
  868.  
  869. /*
  870.  * The Domain Table and its associated routines
  871.  */
  872.  
  873. static struct domains
  874. {
  875.     char dom[50];
  876.     char pre[50];
  877.     char suf[50];
  878.     char map[50];
  879. } domtab[100];
  880.  
  881. /* Inline routine to copy a domain into the domain table */
  882.  
  883. #define DOMCPY(fld) { int i = 0; q=dp->fld; while (*p!=','&&*p!='\n'&&*p) \
  884.             {*q++ = *p++; if (i++>=48) break;} \
  885.             *q++ = '\0'; if (!*p) { \
  886.             fprintf(stderr,"opath: fld(s) missing in %s at %s\n", \
  887.             s, buf); \
  888.             dp++; continue;} p++; }
  889.  
  890. /* Load the domain table from disk */
  891.  
  892. static int
  893. loaddomtab(s)
  894. char *s;
  895. {
  896. XFILE *f;
  897. char buf[100];
  898. register char *p,*q;
  899. struct domains *dp;
  900.  
  901.     f = fopen(s,"r");
  902.     if (f==NULL)
  903.     {
  904.         fprintf(stderr,"opath: can't open domain file '%s'\n",s);
  905.         exit(1);
  906.     }
  907.  
  908.     dp = domtab;
  909.  
  910.     while (fgets(buf,100,f))
  911.     {
  912.         if (buf[0]=='#') continue; /* comments start with "#" */
  913.         p = buf;
  914.         DOMCPY(dom);
  915.         DOMCPY(pre);
  916.         DOMCPY(suf);
  917.         DOMCPY(map);
  918.         if (dp->map[0] == '\0')
  919.         {
  920.             fprintf(stderr,"opath: bad route template in %s\n",s);
  921.             strcpy(dp->map,"Invalid");
  922.         }
  923.         dp++;
  924.     }
  925.  
  926.     dp->map[0] = '\0';  /* mark end of table */
  927.     fclose(f);
  928.  
  929.     return(0);
  930. }
  931.  
  932. /* Get a UUCP path from the pathalias database 
  933.  * and compensate for the format.
  934.  * Typically the format is
  935.  * site1!site2!site3!%s to be used in *printf statements.
  936.  * We don't want the !%s, so we cut it off.
  937.  * Pretty gross, but it works.
  938.  */
  939.  
  940. static char *
  941. gpath(s)
  942. char *s;
  943. {
  944. static char path[100];
  945. int getpath(),x;
  946.     getpath(s,&path[0],paths);
  947.         x=strindex(&path[0],"!%s");
  948.     if (x >0) path[x] = '\0';
  949. #ifdef DEBUG
  950.     if (Debug>1)fprintf(stderr,"Getpath returns: %s\n",&path[0]);
  951. #endif
  952.     return(&path[0]);
  953. }
  954.  
  955. /* returns location of tx in sx */
  956. strindex(sx,tx)
  957. char * sx, *tx;
  958. {
  959.     int i,n;
  960.     n = strlen(tx);
  961.     for (i=0;sx[i] != '\0'; i++)
  962.         if (strncmp(sx+i,tx,n) ==0)
  963.             return(i);
  964.     return (-1);
  965. }
  966.  
  967. /* String compare: entire first argument must match suffix of 2nd argument */
  968.  
  969. static int
  970. domcmp(ss,tt)
  971. char *ss, *tt;
  972. {
  973. char *s, *t;
  974. int cmp;
  975.  
  976.     s = ss + strlen(ss) - 1;
  977.     t = tt + strlen(tt) - 1;
  978.  
  979.     do
  980.     {
  981.         if (*s - *t) break;
  982.         s--;
  983.         t--;
  984.     } while (s >= ss);
  985.  
  986.     if (++s == ss) return(0);
  987.     else return(1);
  988. }
  989.  
  990. /* Look up a domain, and by side effect set prefix and suffix appropriately */
  991.  
  992. char *domain(s)
  993. char *s;
  994. {
  995. struct domains *d;
  996. char *p;
  997. static int loaded = 0;
  998.  
  999.     if (!loaded++) loaddomtab(ConfFile);
  1000.  
  1001.     if (*s!='.') /* default to UUCP domain */
  1002.     {
  1003.         prefix[0]=suffix[0]='\0';
  1004.         return("%R!%U");
  1005.     }
  1006.  
  1007.     for (p=s; *p; p++) if (*p>='a' && *p<='z') *p -= 'a'-'A';
  1008.  
  1009.     for (d = &domtab[0]; (int)d->map[0]; d++)
  1010.     {
  1011.         if (domcmp(d->dom,s)==0) break;
  1012.     }
  1013.  
  1014.     strcpy(prefix,(d->pre[0]=='>')? gpath(&d->pre[1]) : d->pre);
  1015.     strcpy(suffix,d->suf);
  1016.  
  1017.     return(d->map);
  1018. }
  1019.  
  1020. /* opath: generates a UUCP path from an RFC-822 address */
  1021.  
  1022. #define COPYON(s) {char *r; r=s; while (*r) *p++ = *r++; *p = '\0';}
  1023.  
  1024. char *
  1025. opath(s)
  1026. char *s;
  1027. {
  1028. char user[50],site[50];
  1029. static char cm[150];
  1030. XFILE *f;
  1031. char *p, *q, *t;
  1032. char *d;
  1033. int i;
  1034. int found;
  1035. char *suf;
  1036.  
  1037.     for (p=user,q=s;(*p = *q)!='@'; p++,q++)
  1038.         if (*q=='\0') return(s);
  1039.     *p = '\0';
  1040.  
  1041.     strcpy(fullsite,++q);
  1042.  
  1043.     for (p=site;(*p = *q)!='.'; p++,q++)
  1044.         if (*q=='\0') break;
  1045.     *p = '\0';
  1046.  
  1047.     d = domain(q);
  1048.  
  1049.     if (d[0]=='\0') return(s); /* unknown domain - do nothing */
  1050.  
  1051.     for (p=pval, q=d; *q; q++)
  1052.     {
  1053.         if (*q=='%')
  1054.         {
  1055.             switch(*++q)
  1056.             {
  1057.             case 'P':
  1058.                 COPYON(prefix);
  1059.                 break;
  1060.  
  1061.             case 'S':
  1062.                 COPYON(suffix);
  1063.                 break;
  1064.  
  1065.             case 'U':
  1066.                 COPYON(user);
  1067.                 break;
  1068.  
  1069.             case 'N':
  1070.                 COPYON(site);
  1071.                 break;
  1072.  
  1073.             case 'D':
  1074.                 COPYON(fullsite);
  1075.                 break;
  1076.  
  1077.             case 'R':
  1078.                 COPYON(gpath(site));
  1079.                 break;
  1080.  
  1081.             case '%':
  1082.                 *p++ = '%';
  1083.                 break;
  1084.             }
  1085.         }
  1086.         else
  1087.             *p++ = *q;
  1088.     }
  1089.  
  1090.     return(pval);
  1091. }
  1092.  
  1093. /* oupath: generates a uucp path from a (possibly disconnected) uucp path */
  1094.  
  1095. char *oupath(s)
  1096. char *s;
  1097. {
  1098. char *p,*q;
  1099. static char adr[100];
  1100. char first[100];
  1101. int found;
  1102.  
  1103.     for (p=s,q=first,found=0; *p!='!' && *p!='\0'; p++)
  1104.     {
  1105.         if (*p=='.') found++;
  1106.         *q++ = *p;
  1107.     }
  1108.     if (*p=='\0') return (s);
  1109.  
  1110.     *q = '\0';
  1111.  
  1112.     if (found)
  1113.     {
  1114.         strcpy(adr,++p);
  1115.         strcat(adr,"@");
  1116.         strcat(adr,first);
  1117.         return(opath(adr));
  1118.     }
  1119.     else
  1120.     {
  1121.     int i;
  1122.         strcpy(adr,gpath(first));
  1123.         strcat(adr,/* ++ */p);
  1124.  
  1125.         return(adr);
  1126.     }
  1127. }
  1128.  
  1129.  
  1130. opathlog(fmt,a,b,c,d)
  1131. char *fmt;
  1132. int a,b,c,d;
  1133. {
  1134. XFILE *f;
  1135.  
  1136.     f = fopen(logfile,"a");
  1137.     if (f==NULL) return;
  1138.  
  1139.     fprintf(f,fmt,a,b,c,d);
  1140.     fclose(f);
  1141. }
  1142. #endif
  1143. SHAR_EOF
  1144. if test 5753 -ne "`wc -c < 'opath.c'`"
  1145. then
  1146.     echo shar: error transmitting "'opath.c'" '(should have been 5753 characters)'
  1147. fi
  1148. fi # end of overwriting check
  1149. echo shar: extracting "'palias'" '(151 characters)'
  1150. if test -f 'palias'
  1151. then
  1152.     echo shar: will not over-write existing file "'palias'"
  1153. else
  1154. sed 's/^X//' << \SHAR_EOF > 'palias'
  1155. neuro1 %s
  1156. rice  rice!%s
  1157. baylor baylor!%s
  1158. kitty baylor!kitty!%s
  1159. shell shell!%s
  1160. decwrl shell!ihnp4!decwrl!%s
  1161. ihnp4 shell!ihnp4!%s
  1162. psuvax shell!psuvax!%s
  1163. SHAR_EOF
  1164. if test 151 -ne "`wc -c < 'palias'`"
  1165. then
  1166.     echo shar: error transmitting "'palias'" '(should have been 151 characters)'
  1167. fi
  1168. fi # end of overwriting check
  1169. echo shar: extracting "'rmail.c'" '(2622 characters)'
  1170. if test -f 'rmail.c'
  1171. then
  1172.     echo shar: will not over-write existing file "'rmail.c'"
  1173. else
  1174. sed 's/^X//' << \SHAR_EOF > 'rmail.c'
  1175. #ifndef lint
  1176. static char rcsid[]="$Header: rmail.c,v 1.3 85/11/08 03:05:31 sob RELEASE $";
  1177.  
  1178. #endif
  1179.  
  1180. /*
  1181. **  RMAIL -- UUCP mail server.
  1182. **
  1183. **    This program reads the >From ... remote from ... lines that
  1184. **    UUCP is so fond of and turns them into something reasonable.
  1185. **    It calls uumail giving it a -f option built from these
  1186. **    lines.
  1187. */
  1188.  
  1189. #define _DEFINE
  1190.  
  1191. #include "uuconf.h"
  1192. extern FILE *popen();
  1193. extern char *index();
  1194. extern char *rindex();
  1195.  
  1196. # define MAILER    "/usr/lib/uucp/uumail"
  1197.  
  1198. main(argc, argv)
  1199.     char **argv;
  1200. {
  1201.     FILE *out;    /* output to mail handler */
  1202.     char lbuf[512];    /* one line of the message */
  1203.     char from[512];    /* accumulated path of sender */
  1204.     char ufrom[64];    /* user on remote system */
  1205.     char sys[64];    /* a system in path */
  1206.     char junk[512];    /* scratchpad */
  1207.     char cmd[2000];
  1208.     register char *cp;
  1209.     register char *uf;    /* ptr into ufrom */
  1210.     int i;
  1211.  
  1212. # ifdef DEBUG
  1213.     if (argc > 1 && strcmp(argv[1], "-T") == 0)
  1214.     {
  1215.         Debug = TRUE;
  1216.         argc--;
  1217.         argv++;
  1218.     }
  1219. # endif DEBUG
  1220.  
  1221.     if (argc < 2)
  1222.     {
  1223.         fprintf(stderr, "Usage: rmail user ...\n");
  1224.         exit(EX_USAGE);
  1225.     }
  1226.  
  1227.     (void) strcpy(from, "");
  1228.     (void) strcpy(ufrom, "/dev/null");
  1229.  
  1230.     for (;;)
  1231.     {
  1232.         (void) fgets(lbuf, sizeof lbuf, stdin);
  1233.         if (strncmp(lbuf, "From ", 5) != 0 && strncmp(lbuf, ">From ", 6) != 0)
  1234.             break;
  1235.         (void) sscanf(lbuf, "%s %s", junk, ufrom);
  1236.         cp = lbuf;
  1237.         uf = ufrom;
  1238.         for (;;)
  1239.         {
  1240.             cp = index(cp+1, 'r');
  1241.             if (cp == NULL)
  1242.             {
  1243.                 register char *p = rindex(uf, '!');
  1244.  
  1245.                 if (p != NULL)
  1246.                 {
  1247.                     *p = '\0';
  1248.                     if (uf != NULL) 
  1249.                         (void) strcpy(sys, uf);
  1250.                     else
  1251.                         gethostname(sys,32);
  1252.                     uf = p + 1;
  1253.                     break;
  1254.                 }
  1255.                 cp = "remote from somewhere";
  1256.             }
  1257. #ifdef DEBUG
  1258.             if (Debug)
  1259.                 printf("cp='%s'\n", cp);
  1260. #endif
  1261.             if (strncmp(cp, "remote from ", 12)==0)
  1262.                 break;
  1263.         }
  1264.         if (cp != NULL)
  1265.             (void) sscanf(cp, "remote from %s", sys);
  1266.         (void) strcat(from, sys);
  1267.         (void) strcat(from, "!");
  1268. #ifdef DEBUG
  1269.         if (Debug)
  1270.             printf("ufrom='%s', sys='%s', from now '%s'\n", uf, sys, from);
  1271. #endif
  1272.     }
  1273.     (void) strcat(from, uf);
  1274.  
  1275. /*    (void) sprintf(cmd, "exec %s -em -f%s", MAILER, from);*/
  1276.     (void) sprintf(cmd, "exec %s -f%s", MAILER,from);
  1277.     while (*++argv != NULL)
  1278.     {
  1279.         (void) strcat(cmd, " '");
  1280.         if (**argv == '(')
  1281.             (void) strncat(cmd, *argv + 1, strlen(*argv) - 2);
  1282.         else
  1283.             (void) strcat(cmd, *argv);
  1284.         (void) strcat(cmd, "'");
  1285.     }
  1286. #ifdef DEBUG
  1287.     if (Debug)
  1288.         printf("cmd='%s'\n", cmd);
  1289. #endif
  1290.     out = popen(cmd, "w");
  1291.     fputs(lbuf, out);
  1292.     while (fgets(lbuf, sizeof lbuf, stdin))
  1293.         fputs(lbuf, out);
  1294.     i = pclose(out);
  1295.     if ((i & 0377) != 0)
  1296.     {
  1297.         fprintf(stderr, "pclose: status 0%o\n", i);
  1298.         exit(EX_OSERR);
  1299.     }
  1300.  
  1301.     exit((i >> 8) & 0377);
  1302. }
  1303. SHAR_EOF
  1304. if test 2622 -ne "`wc -c < 'rmail.c'`"
  1305. then
  1306.     echo shar: error transmitting "'rmail.c'" '(should have been 2622 characters)'
  1307. fi
  1308. fi # end of overwriting check
  1309. echo shar: extracting "'uuconf.h'" '(2942 characters)'
  1310. if test -f 'uuconf.h'
  1311. then
  1312.     echo shar: will not over-write existing file "'uuconf.h'"
  1313. else
  1314. sed 's/^X//' << \SHAR_EOF > 'uuconf.h'
  1315. /* $Header: uuconf.h,v 1.4 85/10/02 02:16:21 sob Exp $
  1316.  * Configuration for uumail and uupath utilities
  1317.  * Please see the header for makefile for changes you may
  1318.  * need to make there.
  1319.  * $Log:    uuconf.h,v $
  1320.  * Revision 1.4  85/10/02  02:16:21  sob
  1321.  * Added LOCALMAIL definition
  1322.  * 
  1323.  * Revision 1.3  85/09/30  02:50:51  sob
  1324.  * Added pwd.h to list of include files
  1325.  * 
  1326.  * Revision 1.2  85/07/11  19:29:34  sob
  1327.  * *** empty log message ***
  1328.  * 
  1329.  * Revision 1.1  85/07/11  19:22:20  sob
  1330.  * Initial revision
  1331.  * 
  1332.  */
  1333. #include <stdio.h>
  1334. #include <ctype.h>
  1335. #include <pwd.h>
  1336. #include <signal.h>
  1337. #include <setjmp.h>
  1338.  
  1339. /*
  1340.  * sysexits is a file of exit codes that are used in sendmail
  1341.  * and other programs ...
  1342.  */
  1343. #include <sysexits.h>
  1344. /* if you don't have sysexits.h here are the useful parts */
  1345. #ifndef EX_BASE
  1346.  
  1347. # define EX_OK        0    /* successful termination */
  1348.  
  1349.  
  1350. # define EX_USAGE    64    /* command line usage error */
  1351. # define EX_DATAERR    65    /* data format error */
  1352. # define EX_NOINPUT    66    /* cannot open input */
  1353. # define EX_NOHOST    68    /* host name unknown */
  1354. # define EX_UNAVAILABLE    69    /* service unavailable */
  1355. # define EX_SOFTWARE    70    /* internal software error */
  1356. # define EX_OSERR    71    /* system error (e.g., can't fork) */
  1357. # define EX_OSFILE    72    /* critical OS file missing */
  1358. # define EX_CANTCREAT    73    /* can't create (user) output file */
  1359. # define EX_IOERR    74    /* input/output error */
  1360. #endif
  1361.  
  1362. typedef char bool;
  1363.  
  1364. #ifdef DBM
  1365. #include <dbm.h>
  1366. #endif
  1367.  
  1368. #ifdef SYSIII
  1369. #define index strchr
  1370. #define rindex strrchr
  1371. #include <sys/utsname.h>
  1372. #endif
  1373.  
  1374. #define NAMESIZ 32 /* system name size */
  1375. #define PATHSIZ 16*NAMESIZ /* path length */
  1376.  
  1377. #define TRUE    1
  1378. #define FALSE    0
  1379.  
  1380. /* Here's where you should put in the the name of the file
  1381.  * in which the uucpmap data is kept.
  1382.  * For those using DBM, this will be the root filename for the database
  1383.  * (eg... file.pag and file.dir with root name file)
  1384.  */
  1385.  
  1386. #define DATABASE "/usr/lib/uucp/palias"
  1387. #define CONFIGFILE "/usr/lib/uucp/domains"
  1388. #define LOGFILE "/usr/adm/uumail.log"
  1389. /* this needs to be a printf-like string to deliver LOCAL mail */
  1390. /* usually this is either /bin/mail or /bin/binmail */
  1391.  
  1392. #define LOCALMAIL "/bin/bellmail %s"
  1393.  
  1394. #ifdef _DEFINE
  1395. #define EXTERN 
  1396. #else
  1397. #define EXTERN extern
  1398. #endif
  1399.  
  1400. EXTERN int Debug;
  1401. EXTERN char *paths;
  1402. EXTERN char *ConfFile;
  1403. EXTERN char Myname[NAMESIZ];
  1404. EXTERN char *logfile;
  1405. EXTERN char    OpMode;        /* operation mode, see below */
  1406. /* These don't do anything yet.... next time they will do something */
  1407. #define MD_DELIVER    'm'        /* be a mail sender */
  1408. #define MD_ARPAFTP    'a'        /* old-style arpanet protocols */
  1409. #define MD_SMTP        's'        /* run SMTP on standard input */
  1410. #define MD_DAEMON    'd'        /* run as a daemon */
  1411. #define MD_VERIFY    'v'        /* verify: don't collect or deliver */
  1412. #define MD_TEST        't'        /* test mode: resolve addrs only */
  1413. #define MD_INITALIAS    'i'        /* initialize alias database */
  1414. #define MD_PRINT    'p'        /* print the queue */
  1415. #define MD_FREEZE    'z'        /* freeze the configuration file */
  1416. SHAR_EOF
  1417. if test 2942 -ne "`wc -c < 'uuconf.h'`"
  1418. then
  1419.     echo shar: error transmitting "'uuconf.h'" '(should have been 2942 characters)'
  1420. fi
  1421. fi # end of overwriting check
  1422. echo shar: extracting "'uumail.1'" '(2272 characters)'
  1423. if test -f 'uumail.1'
  1424. then
  1425.     echo shar: will not over-write existing file "'uumail.1'"
  1426. else
  1427. sed 's/^X//' << \SHAR_EOF > 'uumail.1'
  1428. X.TH "UUMAIL" "8" "Baylor College of Medicine"
  1429. X.fi
  1430. X.ad b
  1431. X.SH NAME
  1432. uumail \- rewrite address & route mail using uucpmap database 
  1433. X.br
  1434. uupath \- print the uucp path to a host
  1435. X.SH SYNOPSIS
  1436. X.B uumail [ \fIoptions\fR ] \fIaddress\fR
  1437. X.br
  1438. X.B uupath \fIhostname\fR
  1439. X.SH DESCRIPTION
  1440. X.B Uumail
  1441. is designed to be used as a mail delivery program to correctly
  1442. route mail over uucp connections.
  1443. X.SS Standard Options
  1444. X.IP "-f\fIaddress\fR" 16
  1445. The -f option sets the address of the sender of the mail. If this flag 
  1446. is not used, the sender will be established by usings environmental variables
  1447. (like 
  1448. X.B LOGNAME
  1449. and
  1450. X.B USER
  1451. ) or using getlogin(3).
  1452. X.IP "-m" 16
  1453. The -m option causes the mail to also be sent to the sender of the message.
  1454. X.IP "-c" 16
  1455. The -c option causes
  1456. X.B uucico 
  1457. to be started immediately after queuing the mail.
  1458. The default just queues the mail.
  1459. X.IP "-h" 16
  1460. The -h option causes no From_ line to be added to the beginning of file.
  1461. This is useful when uumail is being used as a mailer for sendmail(8).
  1462. X.SS Compile-time Configurable Options
  1463. X.IP "-d[1-6]" 16
  1464. The -d option turns on the limited debugging facility built into the
  1465. mailer.  In debug mode, the mailer does not actually mail anything, but
  1466. tells you what it would do if it did do it. The level of debugging can
  1467. be set by following the 
  1468. X.I -d
  1469. flag with a number between 1 and 6.
  1470. X.IP "-g[A-Z]" 16
  1471. If your 
  1472. X.B uux(1)
  1473. supports grading of transactions, the -g option can be used to set the
  1474. grade of this mail. A grade of \fIC\fR is used by default.
  1475.  
  1476. X.SS Arguments
  1477. X.IP \fIhost!user\fR 16
  1478. where host is a system node name on the network and user is the login
  1479. name of the addressee.
  1480. X.IP \fIuser@host.domain\fR
  1481. same as above with the addition of a domain specifier like
  1482. X.B .ARPA, .GOV, .COM, .EDU
  1483. etc.
  1484. X.SH FILES
  1485. X.IP "/usr/lib/uucp/palias" 20
  1486. Path file produced by pathalias.
  1487. X.IP "/usr/lib/uucp/uucp/domains" 20
  1488. Domain rewriting rules for opath(3).
  1489. X.IP "/usr/adm/uumail.log" 20
  1490. Log of uumail activity.
  1491. X.SH "SEE ALSO"
  1492. pathalias(1), Pnews(1), Rnmail(1), rn(1), postnews(1), readnews(1),
  1493. opath(3), sendmail(8)
  1494.  
  1495. X.SH AUTHORS
  1496. X.br
  1497. XStan Barber, Baylor College of Medicine
  1498. X.br
  1499. Getpath routine by John Donnelly, University of Illinois
  1500. X.br
  1501. Gethostname routine by Peter Honeyman, Princeton
  1502. X.br
  1503. Opath routine by Eric Roskos, Perkin-Elmer
  1504.  
  1505. SHAR_EOF
  1506. if test 2272 -ne "`wc -c < 'uumail.1'`"
  1507. then
  1508.     echo shar: error transmitting "'uumail.1'" '(should have been 2272 characters)'
  1509. fi
  1510. fi # end of overwriting check
  1511. echo shar: extracting "'uumail.c'" '(11965 characters)'
  1512. if test -f 'uumail.c'
  1513. then
  1514.     echo shar: will not over-write existing file "'uumail.c'"
  1515. else
  1516. sed 's/^X//' << \SHAR_EOF > 'uumail.c'
  1517. /*
  1518.  *  U U M A I L
  1519.  *  This program when invoked in the form:
  1520.  *  uumail host!user will consult the local usemap for
  1521.  *  the proper routing.
  1522.  * 
  1523.  *  If it finds it, it will invoke the proper uux call
  1524.  *  to send the mail.
  1525.  *  Otherwise it aborts with an error 68 (host unknown)
  1526.  * $Log:    uumail.c,v $
  1527.  * Revision 2.7  85/11/18  12:36:48  sob
  1528.  * Added the -h option to cause uumail NOT to add a From_ line.
  1529.  * 
  1530.  * Revision 2.6  85/11/14  20:20:06  sob
  1531.  * Added #ifdef DEBUG to allow compiliation with out DEBUG installed
  1532.  * 
  1533.  * Revision 2.5  85/11/14  20:14:11  sob
  1534.  * Another little buggie in the log format...sheesh.
  1535.  * 
  1536.  * Revision 2.4  85/11/13  15:53:18  sob
  1537.  * Reformated the log file a little bit.
  1538.  * 
  1539.  * Revision 2.3  85/11/08  03:03:51  sob
  1540.  * This is the release version.
  1541.  * 
  1542.  * 
  1543.  * Revision 2.2  85/09/30  02:51:18  sob
  1544.  * This version uses opath when defined during compile time.
  1545.  * With a bit of cleaning up, this is a release version.
  1546.  * 
  1547.  * Revision 2.1  85/09/30  02:46:06  sob
  1548.  * *** empty log message ***
  1549.  * 
  1550.  * Revision 2.0  85/09/09  18:22:56  UUCP
  1551.  * *** empty log message ***
  1552.  * 
  1553.  * Revision 2.0  85/09/09  18:22:56  UUCP
  1554.  * Added flags to conform with sendmail. Also updated the flags it could send
  1555.  * to uux to conform with 4.3 uux command.
  1556.  * Will add name resolution and header checking.
  1557.  * Also will allow multiple addresses per line.
  1558.  * 
  1559.  * Revision 1.7  85/08/03  00:49:14  UUCP
  1560.  * Cleaned up with lint.
  1561.  * Stan Barber
  1562.  * 
  1563.  * Revision 1.6  85/07/11  19:30:00  sob
  1564.  * changed PATHSIZE to PATHSIZ to conform with uupath
  1565.  * 
  1566.  * Revision 1.5  85/07/11  18:08:13  sob
  1567.  * This one works both as uumail and uupath!
  1568.  * Stan
  1569.  * 
  1570.  * Revision 1.4  85/07/10  18:35:05  sob
  1571.  * moved DBM to getpath
  1572.  * Stan Barber
  1573.  * 
  1574.  * Revision 1.3  85/07/09  01:28:14  sob
  1575.  * First attempt to integrate uupath
  1576.  * Not successful. Changed PATHALIAS define
  1577.  * to DBM... will ultimately alter getpath as well
  1578.  * added gethostname call to fill in for local host.
  1579.  * 
  1580.  * Revision 1.2  85/07/08  05:29:16  sob
  1581.  * This one works with pathalias database...
  1582.  * need to modify to substitue for uupath.
  1583.  * Stan
  1584.  * 
  1585.  * Revision 1.1  85/07/08  03:11:10  sob
  1586.  * Initial revision
  1587.  * 
  1588.  */
  1589. #define _DEFINE
  1590.  
  1591. #include "uuconf.h"
  1592.  
  1593.  
  1594. EXTERN bool uupath;
  1595. extern int      errno;
  1596. extern struct passwd *getpwuid();
  1597. extern FILE    *popen();
  1598. extern char     *ctime();
  1599. extern char    *getlogin();
  1600. extern char    *index();
  1601. extern char    *rindex();
  1602. extern char    *malloc();
  1603. extern char     *getenv();
  1604. EXTERN char    progname[12];
  1605. EXTERN char  *paths;
  1606. int local;
  1607. char templet[64];
  1608. char * from;
  1609.  
  1610.  
  1611. static char Version[] ="$Header: uumail.c,v 2.7 85/11/18 12:36:48 sob Exp $";
  1612.  
  1613. main(argc, argv)
  1614.     char **argv;
  1615. {
  1616.     FILE *out, *tmpf;    /* output to uux, temp file */
  1617.     char lbuf[512]; /* for pipe to uux */
  1618.     char sender[512];    /* accumulated path of sender */
  1619.     char sys[64];    /* a system in path */
  1620.     char cmd[2000];
  1621.     char **av;
  1622.     int i,
  1623.             error = 0,
  1624.             bangcnt, hopcount = 30,
  1625.         metoo=0, noheader = 0,
  1626.         startuux ;
  1627.         
  1628.     char    c,
  1629.             grade = 'C',
  1630.        name[20],             /* The system name (if any) */
  1631.        *fname,
  1632.        *path,            /* uupath to the system */
  1633.            *sysname,            /* points to the system name */
  1634.            *p, *q,            /* tmp pointer to argv's */
  1635.        *rsys,
  1636.        *FullName;
  1637.        bool GrabTo,safecf,NoAlias;
  1638.        extern intsig();
  1639.  
  1640.     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  1641.         (void) signal(SIGINT, intsig);
  1642.     if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
  1643.         (void) signal(SIGHUP, intsig);
  1644.     (void) signal(SIGTERM, intsig);
  1645.     (void) signal(SIGPIPE, SIG_IGN);
  1646.  
  1647.  
  1648.     for (i = 3; i < 20; i++)
  1649.         (void) close(i);
  1650.     errno = 0;
  1651.     gethostname(Myname,32);
  1652.     paths=DATABASE;
  1653.     logfile=LOGFILE;
  1654.     argv[argc] = NULL;
  1655.     av = argv;
  1656.     p = rindex(*av, '/');
  1657.     if (p++ == NULL)
  1658.         p = *av;
  1659.     strcpy(progname ,p);
  1660.     if(strcmp(p,"uupath") == 0)
  1661.         uupath = TRUE;
  1662.     while ((p = *++av) != NULL && p[0] == '-')
  1663.     {
  1664.         switch (p[1])
  1665.         {
  1666.  
  1667.           case 'C':    /* select configuration file */
  1668.             ConfFile = &p[2];
  1669.             safecf = FALSE;
  1670.  
  1671.             break;
  1672.  
  1673.           case 'g':   /* set grade */
  1674.             grade = p[2];
  1675.             break;
  1676.     
  1677. # ifdef DEBUG
  1678.           case 'd':    /* debug */
  1679.             Debug= atoi(&p[2]);
  1680.             if (Debug == 0) Debug = 1;
  1681.             setbuf(stdout, (char *) NULL);
  1682.             printf("Version %s\n", Version);
  1683.             break;
  1684. # endif DEBUG
  1685.  
  1686.           case 'f':    /* from address */
  1687.           case 'r':    /* obsolete -f flag */
  1688.             p += 2;
  1689.             if (*p == '\0' && ((p = *++av) == NULL || *p == '-'))
  1690.             {
  1691.                 p = *++av;
  1692.                 if (p == NULL || *p == '-')
  1693.                 {
  1694.                     syserr("No \"from\" person");
  1695.                     av--;
  1696.                     break;
  1697.                 }
  1698.             }
  1699.             if (from != NULL)
  1700.             {
  1701.                 syserr("More than one \"from\" person");
  1702.                 break;
  1703.             }
  1704.             from = p;
  1705.             break;
  1706.  
  1707.           case 'w':    /* just print the path */
  1708.             uupath = TRUE;
  1709.             break;
  1710.           case 'm':    /* send to me too */
  1711.             metoo = TRUE;
  1712.             break;
  1713.           case 'c':    /* connect to non-local mailers */
  1714.             startuux= TRUE;
  1715.             break;
  1716.           case 'h':    /* don't add a From line */
  1717.             noheader = TRUE;
  1718.             break;
  1719.             }
  1720.     
  1721.         }
  1722.  
  1723.     if(*av==NULL && GrabTo!= TRUE)
  1724.     {
  1725.         fprintf(stderr,"Usage: %s [flags] address\n",progname);
  1726.         exit(EX_USAGE);
  1727.     }
  1728.  
  1729.     if (ConfFile == NULL) ConfFile = CONFIGFILE;
  1730.  
  1731.     if(from==NULL || strlen(from) == 0){
  1732.         if (((from = getenv("LOGNAME")) == NULL) || (strlen(from) == 0))
  1733.             from = getenv("USER");
  1734.         if ((from == NULL) || (strlen(from) == 0))
  1735.             from = getlogin();
  1736.         if ((from == NULL) || (strlen(from) == 0))
  1737.             from = getpwuid(geteuid())->pw_name;
  1738.     }
  1739.  
  1740. if (!uupath)
  1741. {    
  1742. #ifdef DEBUG
  1743.     if (Debug) printf("Mail from %s\n",from);
  1744. #endif
  1745.     /*
  1746.      * Make temporary file for letter
  1747.      * (I wish ACCESS(2) would take care of this better !!)
  1748.      */
  1749.     if ((p=getenv("HOME"))== NULL)
  1750.         p="/tmp";
  1751.     sprintf(&templet[0],"%s/.uumXXXXXX",p);
  1752.     mktemp(templet);
  1753.     unlink(templet);
  1754.     if ((i=open(templet,2)) < 0)
  1755.         {
  1756.             p="/tmp";
  1757.     
  1758.             sprintf(&templet[0],"%s/.uumXXXXXX",p);
  1759.             mktemp(templet);
  1760.             unlink(templet);
  1761.         }
  1762.     else
  1763.         {
  1764.             close(i);
  1765.             unlink(templet);
  1766.         }
  1767. #ifdef DEBUG
  1768.     if (Debug>2) printf("Temp file is %s\n",templet);
  1769. #endif
  1770.     if((tmpf = fopen(templet, "w")) == NULL){
  1771.         fprintf(stderr, "%s : can't open %s for writing\n", progname,templet);
  1772.         fclose(stdin);
  1773.         exit(EX_CANTCREAT);
  1774.  
  1775.         }
  1776.     while(fgets(lbuf,sizeof lbuf,stdin))
  1777.         fputs(lbuf,tmpf);
  1778.     fclose(tmpf);
  1779.     fclose(stdin);
  1780. /* file now saved */
  1781.     if((tmpf = fopen(templet, "r")) == NULL){
  1782.         fprintf(stderr, "%s : can't open %s for reading\n", progname,templet);
  1783.         exit(EX_OSERR);
  1784.     }
  1785.     
  1786. }    
  1787.     (void) strcpy(sender, "");
  1788.  
  1789.     path = malloc(PATHSIZ);
  1790.  
  1791.     av--;
  1792.  
  1793.     if(metoo)
  1794.     {
  1795.     *av = from;
  1796.     av --;
  1797.     }
  1798.     
  1799.     while (av++ != NULL && *av != NULL)
  1800.     {
  1801.     local = bangcnt = 0;
  1802.     
  1803.     
  1804.     q = p = *av;
  1805.     
  1806.     sysname = &name[0];
  1807.  
  1808.     
  1809.     if (uupath) 
  1810.  
  1811.     {
  1812.     (void) strcpy(sysname ,p);
  1813. #ifdef OPATH
  1814.     if ((error = getpath (&name[0], path)) != EX_OK)
  1815.         {
  1816.         if (error == EX_NOHOST) fprintf (stderr, "System %s not found in network map\n", &name[0]);
  1817.         if (error == EX_NOINPUT) fprintf(stderr,"Database %s could not be opened\n",paths);
  1818.         exit(EX_NOHOST);
  1819.         }
  1820.     }
  1821.     else 
  1822.     if (index(p,'@') == NULL) strcpy(path,oupath(p)); 
  1823.         else strcpy(path,opath(p));
  1824. #ifdef DEBUG
  1825.     if (Debug >1) fprintf(stderr,"Opath returns %s\n",path);
  1826. #endif
  1827.  
  1828.     if (path[0] == '!')  /* no match in pathalias database */
  1829.     {
  1830.         deadletter(tmpf,local);
  1831.         unlink(templet);
  1832.         exit(EX_NOHOST);
  1833.     }
  1834.    
  1835.    if (strcmp(path,p) == 0)
  1836.     {
  1837.     strcpy(path,Myname);
  1838.     local = 1;
  1839.     }
  1840.  
  1841. #else
  1842.     }
  1843.     else
  1844. {
  1845.     do                        /* count bangs */
  1846.         {
  1847.             while (((c = *p++) != '!') && (c != '\0'));
  1848.                 if (c == '!') bangcnt++;
  1849.         }
  1850.     while (c != '\0' && bangcnt == 1);
  1851.         ;
  1852.     if (bangcnt >= 1)                /* expand path */
  1853.         {
  1854.             while ((*sysname++ = *q++) != '!');
  1855.                 *--sysname = '\0';
  1856.  
  1857.             }
  1858.     /* insert code here to look at uucp neighbors & local host */
  1859.     if (bangcnt == 0) {
  1860.             strcpy(sysname,Myname);
  1861.             local = 1;
  1862.             }
  1863.     }
  1864. #ifdef DEBUG
  1865.     if (Debug>1) printf("sysname = %s\n",&name[0]);
  1866. #endif
  1867.     
  1868.     if (!local && (error = getpath (&name[0], path)) != EX_OK)
  1869.         {
  1870.         if (error == EX_NOHOST) fprintf (stderr, "System %s not found in network map\n", &name[0]);
  1871.         if (error == EX_NOINPUT) fprintf(stderr,"Database %s could not be opened\n",paths);
  1872.         exit(EX_NOHOST);
  1873.         }
  1874.  
  1875.        if (local) path = sysname;
  1876. #endif
  1877.  
  1878. #ifdef DEBUG
  1879.        if(Debug>1) printf("Path = %s\n",path);
  1880. #endif
  1881.  
  1882.     p = q;                    /* save name */
  1883.     for (i = 0; i < 1 && *p != '\0'; p++)
  1884.         if (*p == '/')
  1885.         i++;
  1886.     fname = &sender[0];
  1887.  
  1888.         if (uupath)
  1889.         sprintf(fname,path,"username");
  1890.     else
  1891.         sprintf(fname,path,q);
  1892.  
  1893.     p = &sender[0];
  1894.     rsys = &sys[0];
  1895.  
  1896.     if (!local)
  1897.         {
  1898.         while((*rsys++ = *p++) != '!');
  1899.         *--rsys = '\0';
  1900.         }
  1901.         else
  1902. /* local host, remove @ sign */
  1903.         {
  1904.         strcpy(rsys,*av);
  1905.         q=rsys;
  1906.         if (index(rsys,'@') != 0)
  1907.             { 
  1908.                 while (*q++ !='@');
  1909.                 *--q='\0';
  1910.             }
  1911.         /* assume that if it has a bang in it uux
  1912.             will either reject it or know what to do with it */
  1913.         /* this is a little gross */
  1914.         if ((q = index(rsys,'!')) != 0)
  1915.             {
  1916.             local=0;
  1917.             strcpy(&sys[0],rsys);
  1918.             sys[q-rsys]='\0';
  1919.             p=q+1;
  1920.             }
  1921.     }
  1922.         
  1923.     if ((!local && *fname =='\0') || (local && &sys[0]=='\0')) {
  1924.         fprintf(stdout, "null name\n");
  1925.         exit(EX_DATAERR);
  1926.     }
  1927. #ifdef DEBUG
  1928.     if (Debug>3)
  1929.         printf("p = %s sys = %s fname = %s\n",p, &sys[0],fname);
  1930. #endif
  1931.  
  1932.     if (uupath)
  1933.         {
  1934.         printf ("Path to %s:  %s\n", *av, fname);
  1935.         continue;
  1936.         }
  1937.     else
  1938.     {
  1939.         if (local)
  1940.             sprintf(cmd, LOCALMAIL, &sys[0]);
  1941.         else {
  1942.             strcpy(cmd,"uux - ");
  1943.         if (!startuux)
  1944.             strcat(cmd,"-r");
  1945. #ifndef NORETURN
  1946.         if (from)
  1947.             {
  1948.             strcat(cmd," -a");
  1949.             strcat(cmd,from);
  1950.             }
  1951. #endif
  1952. #ifndef NOGRADE
  1953.         if (grade)
  1954.             {
  1955.             char work[10];
  1956.             sprintf(work," -g%c",grade);
  1957.             strcat(cmd,work);
  1958.             }
  1959. #endif        
  1960.         if (index(p, '!'))
  1961.             {
  1962.                 char work[100];
  1963.                 sprintf(work, " %s!rmail \\(%s\\)",  &sys[0], p);
  1964.                 strcat(cmd,work);
  1965.             }
  1966.         else
  1967.             {
  1968.                 char work[100];
  1969.                 sprintf(work, " %s!rmail %s", &sys[0], p);
  1970.                 strcat(cmd,work);
  1971.             }
  1972.         }
  1973. #ifdef DEBUG
  1974.     if (Debug) fprintf(stderr,"Command is %s\n",cmd);
  1975. #endif
  1976.         rewind(tmpf);
  1977. #ifdef DEBUG
  1978.         if (Debug)
  1979.             out = fopen("UUMAIL.TEST","w");
  1980.         else
  1981. #endif
  1982.             out = popen(cmd, "w");
  1983. /*        fputs(lbuf, out); */
  1984.         if (!noheader) Putfrom(tmpf,out);
  1985.         while (fgets(lbuf, sizeof lbuf, tmpf))
  1986.             fputs(lbuf, out);
  1987.  
  1988. /* may not be needed */
  1989.         if (local)
  1990.             fprintf(out,"\n.\n");
  1991.  
  1992. #ifdef DEBUG
  1993.         if (Debug)
  1994.             i = fclose(out);
  1995.         else
  1996. #endif
  1997.             i = pclose(out);
  1998.         if ((i & 0377) != 0)
  1999.             {
  2000.                 fprintf(stderr, "pclose: status 0%o\n", i);
  2001.                 deadletter(tmpf,local);
  2002. #ifdef DEBUG
  2003.                 if (Debug <3) unlink(templet);
  2004. #endif
  2005.                 exit(EX_OSERR);
  2006.             }
  2007. #ifdef LOG
  2008.         maillog(cmd);
  2009. #endif
  2010.        }
  2011.     }
  2012. #ifdef DEBUG
  2013.     if (Debug <3) unlink(templet);
  2014. #endif
  2015. exit(EX_OK);
  2016. }
  2017.  
  2018. /* print an error message on stderr */
  2019.  
  2020. syserr(string)
  2021. char * string;
  2022. {
  2023.     fprintf(stderr,"%s\n",string);
  2024. }
  2025.  
  2026. /* make a unix type From line and send it out the stream */
  2027.  
  2028. Putfrom(into,outto)
  2029. XFILE *into, *outto;
  2030. {
  2031.     char    *asctime();
  2032.     struct    tm *bp, *localtime();
  2033.     char    *tp, *zp;
  2034.     int    n,fromflag=0;
  2035.     char buf[128];
  2036.     long iop;
  2037.  
  2038.     /*
  2039.      * Format time
  2040.      */
  2041.     time(&iop);
  2042.     bp = localtime(&iop);
  2043.     tp = asctime(bp);
  2044. /*    zp = tzname[bp->tm_isdst];*/
  2045. /*    sprintf(buf, "%s%s %.16s %.3s %.5s", from, tp, zp, tp+20);*/
  2046.     sprintf(buf, "From %s %.16s %.4s", from, tp, tp+20);
  2047.  
  2048. #ifdef UGLYUUCP
  2049.     if (!local){
  2050.             strcat(buf," remote from ");
  2051.             strcat(buf,Myname);
  2052.            }
  2053. #endif
  2054.     strcat(buf,"\n");
  2055.     write(outto->_file,buf,strlen(buf));
  2056.     fflush(outto);
  2057.  
  2058.     if (fgets(buf,sizeof(buf),into) != NULL)
  2059.     if((strncmp(&buf[0], "From ", 5) == 0 || strncmp(&buf[0], "From:", 5) == 0))
  2060.          write(outto->_file,">",1);
  2061.     
  2062.     write(outto->_file,buf,strlen(buf));
  2063. }
  2064.  
  2065.  
  2066. /* attempt to return dead letter */
  2067. /* we'll do better on this one next time */
  2068.  
  2069. deadletter(retlet, here)
  2070. XFILE *retlet;
  2071. int here;
  2072. {
  2073.     if(getlogin() != NULL) syserr("Letter failed....\n");
  2074. }
  2075.  
  2076. /* go here on a signal we want to catch */
  2077. intsig()
  2078. {
  2079.     unlink(templet);
  2080.     exit(EX_OK);
  2081. }
  2082.  
  2083. /* put command strings in the logfile */
  2084.  
  2085. #ifdef LOG
  2086.  
  2087. maillog(command)
  2088. char * command;
  2089. {
  2090.     FILE *f;
  2091.     char atime[24];
  2092.     long clock;
  2093.     time (&clock);
  2094.     strncpy(atime,ctime(&clock),24);
  2095.  
  2096.     if ((f=fopen(logfile,"a")) != NULL)
  2097.         {
  2098.             fprintf(f,"%s: %s - %s\n",progname,atime,command);
  2099.             fclose(f);
  2100.         }
  2101. }
  2102.  
  2103. #endif
  2104. SHAR_EOF
  2105. if test 11965 -ne "`wc -c < 'uumail.c'`"
  2106. then
  2107.     echo shar: error transmitting "'uumail.c'" '(should have been 11965 characters)'
  2108. fi
  2109. fi # end of overwriting check
  2110. echo shar: extracting "'uupath.1'" '(759 characters)'
  2111. if test -f 'uupath.1'
  2112. then
  2113.     echo shar: will not over-write existing file "'uupath.1'"
  2114. else
  2115. sed 's/^X//' << \SHAR_EOF > 'uupath.1'
  2116. X.TH "UUPATH" "1" "Baylor College of Medicine"
  2117. X.fi
  2118. X.ad b
  2119. X.SH NAME
  2120. uupath \- print mail routing information using uucpmap database
  2121. X.SH SYNOPSIS
  2122. X.B uupath  \fIhost1 host2 host3 ...\fR
  2123. X.SH DESCRIPTION
  2124. X.B Uupath
  2125. is designed to be used to query the uucpmap database for mail routing
  2126. paths used by
  2127. X.I uumail.
  2128. X.SS Arguments
  2129. X.IP "host1 host2 host3 ..."
  2130. where host1, host2, host3 and so on are system node names on the network.
  2131. Many hostnames may be entered as arguements to
  2132. X.I uupath.
  2133.  
  2134. X.SH FILES
  2135. X.IP "/usr/lib/uucp/palias" 
  2136. Path file produced by pathalias.
  2137. X.SH "SEE ALSO"
  2138. pathalias(1), Pnews(1), Rnmail(1), rn(1), postnews(1), readnews(1), uumail(8)
  2139.  
  2140. X.SH AUTHORS
  2141. X.br
  2142. Jeff Donnelly, University of Illinois
  2143. X.br
  2144. XStan Barber, Baylor College of Medicine & Rice University
  2145.  
  2146. SHAR_EOF
  2147. if test 759 -ne "`wc -c < 'uupath.1'`"
  2148. then
  2149.     echo shar: error transmitting "'uupath.1'" '(should have been 759 characters)'
  2150. fi
  2151. fi # end of overwriting check
  2152. echo shar: extracting "'uupath.c'" '(1155 characters)'
  2153. if test -f 'uupath.c'
  2154. then
  2155.     echo shar: will not over-write existing file "'uupath.c'"
  2156. else
  2157. sed 's/^X//' << \SHAR_EOF > 'uupath.c'
  2158. /*
  2159.  * Name: uupath
  2160.  *
  2161.  * Calls getpath to lookup the usenet path
  2162.  *
  2163.  * Author: J. Donnelly  3/82
  2164.  * $Log:    uupath.c,v $
  2165.  * Revision 1.3  85/08/03  01:26:17  UUCP
  2166.  * *** empty log message ***
  2167.  * 
  2168.  * Revision 1.2  85/07/19  17:47:05  UUCP
  2169.  * updated to define Debug for compatability with getpath
  2170.  * 
  2171.  * Revision 1.1  85/07/11  18:35:59  sob
  2172.  * Initial revision
  2173.  * 
  2174.  *
  2175.  */
  2176.  
  2177. #include    "uuconf.h"
  2178. bool Debug;
  2179.  
  2180. static char rcsid[] = "$Header: uupath.c,v 1.3 85/08/03 01:26:17 UUCP Exp $";
  2181.  
  2182. main (argc, argv) char *argv[];
  2183. {
  2184.     char    path[PATHSIZ],work[BUFSIZ];
  2185.     int     i,
  2186.             retval;                    /* value returned from getpath */
  2187.  
  2188.     if (argc < 2)
  2189.     {
  2190.     printf ("Usage: uupath sysname1 sysname2 ...\n");
  2191.     exit (EX_USAGE);
  2192.     }
  2193.  
  2194.     for (i = 1; i < argc; i++)
  2195.     {
  2196.     retval = getpath (argv[i], &path[0],DATABASE);        /* lookup usenet path */
  2197.     if (retval == EX_NOHOST)
  2198.         printf ("Can't find path to %s\n", argv[i]);
  2199.  
  2200.     else
  2201.         if (retval == EX_NOINPUT)
  2202.         {
  2203.         printf ("Can't open the network map\n");
  2204.         exit (EX_TEMPFAIL);
  2205.         }
  2206.  
  2207.         else
  2208.         {
  2209.         sprintf (&work[0],"Path to %s:  %s\n", argv[i], &path[0]);
  2210.             printf(&work[0],"username");
  2211.         }
  2212.     }
  2213. }
  2214. SHAR_EOF
  2215. if test 1155 -ne "`wc -c < 'uupath.c'`"
  2216. then
  2217.     echo shar: error transmitting "'uupath.c'" '(should have been 1155 characters)'
  2218. fi
  2219. fi # end of overwriting check
  2220. #    End of shell archive
  2221. exit 0
  2222.  
  2223.